package com.dek.zk;

import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.CreateMode;

public class NodeManager {

    private ZkClient zkClient = CreateSession.getClient();

    private void create() {
        NodeData nodeData = new NodeData();
        nodeData.setId(1);
        nodeData.setName("dek");
        String path = zkClient.create("/testData", nodeData, CreateMode.PERSISTENT);
        System.out.println("node created " + path);
    }

    private void update() {
        NodeData nodeData = new NodeData();
        nodeData.setId(2);
        nodeData.setName("haq");
        zkClient.writeData("/testData", nodeData);
        System.out.println("updated");
    }

    private void delete() {
        zkClient.delete("/testData");
        System.out.println("deleted");
    }

    public static void main(String[] args) {
        NodeManager manager = new NodeManager();
        manager.create();
        manager.update();
        manager.delete();
    }

}
